import { FilterOptionsWithId, FilterType } from 'common/utils/eq-filter/types';

export interface GraphConfig {
  // base
  width: number;
  height: number;
  isDarkMode?: boolean;
  margin?: MarginInput;

  // axis
  xMin: number;
  xMax: number;
  xInterval?: number | false;
  xLabelPrefix?: string;
  xLabelSuffix?: string;
  xLabelSign?: boolean;
  yMin: number;
  yMax: number;
  yInterval?: number;
  xTransform?: CoordinateTransform;
  yTransform?: CoordinateTransform;
  yLabelPrefix?: string;
  yLabelSuffix?: string;
  yLabelSign?: boolean;

  // styles
  lineWidth?: number;
  gridColor?: string;
  gridColorDark?: string;
  axisColor?: string;
  axisColorDark?: string;
  curveColor?: string;
  curveColorDark?: string;
  fontSize?: number;
  bandFontSize?: number;
  fontWeight?: string;
  fontFamily?: string;
  labelColor?: string;
  labelColorDark?: string;
  backgroundColor?: string;
  backgroundColorDark?: string;
  plotAreaBackgroundColor?: string;
  plotAreaBackgroundColorDark?: string;
  bandsBackgroundColor?: string;
  bandsBackgroundColorDark?: string;
  xLineColor?: string;
  xLineColorDark?: string;
  highlightPointRadius?: number;
  highlightPointBorderWidth?: number;
  highlightPointBorderColor?: string;
  highlightPointBorderColorDark?: string;
  highlightPointBackgroundColor?: string;
  highlightPointBackgroundColorDark?: string;

  // extends
  tooltip?: TooltipConfig;
  interaction?: InteractionConfig;

  // bands
  frequencyBands?: FrequencyBand[];
}

export type MarginInput =
  | number
  | {
      top?: number;
      right?: number;
      bottom?: number;
      left?: number;
    };

export interface Margin {
  top: number;
  right: number;
  bottom: number;
  left: number;
}

export interface FrequencyBand {
  min: number;
  max: number;
  label: string;
}

export interface CoordinateTransform {
  transform: (
    value: number,
    min: number,
    max: number,
    start: number,
    end: number,
  ) => number;
  inverse: (
    pixel: number,
    min: number,
    max: number,
    start: number,
    end: number,
  ) => number;
}

export interface TooltipConfig {
  enabled?: boolean;
}

export interface InteractionConfig {
  snap?: boolean; // allow auto snap
  snapThreshold?: number | ((x: number) => number); // distance threshold for snapping
}

export interface GraphState {
  bounds: Bounds;
  transform: GraphTransform;
}

export interface Bounds {
  xMin: number;
  xMax: number;
  yMin: number;
  yMax: number;
}

export interface GraphTransform {
  scale: { x: number; y: number };
  translate: { x: number; y: number };
}

export interface TooltipState {
  visible: boolean;
  position: { x: number; y: number };
  content: { x: number; y: number; label?: string } | null;
}

export interface Point {
  x: number;
  y: number;
  label?: string;
  data?: any; // extra data
}

export interface EQ {
  frequency: number;
  gain: number;
  q: number;
  filterType: FilterType;
}

export interface FiltersValue {
  freqToDB: API.EvaluationItemChildren; // 原始频响数据
  project: API.EvaluationProject; // 原始频响曲线的设置

  eqs: FilterOptionsWithId[]; // 均衡器设置
  currentEQId?: string; // 当前所选择的均衡器id
}